//导航条JS
var timeout         = 200;
var closetimer		= 0;
var ddmenuitem      = 0;
var current_mouse_over_id = "";

function jsddm_open(){	
	jsddm_canceltimer();
	jsddm_close();
	if($(this).find("a:eq(0)").attr("class") != "active"){
		current_mouse_over_id = $(this).attr("id");
	}
	$(this).find("a:eq(0)").addClass("active");
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close(){	
	if(ddmenuitem) {
		if(current_mouse_over_id != ""){
			$("#"+current_mouse_over_id).find("a:eq(0)").removeClass("active");
		}
		ddmenuitem.css('visibility', 'hidden');
	}
}

function jsddm_click(){	
	current_mouse_over_id = "";
}

function jsddm_timer(){
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer(){
	if(closetimer){	
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

$(document).ready(function(){
	$('.nav > li').bind('mouseover', jsddm_open);
	$('.nav > li').bind('mouseout',  jsddm_timer);
	$('.nav > li').bind('click',  jsddm_click);
});

document.onclick = jsddm_close;

//判断是否是IE
function ifie(){
	return document.all;
}

//设置首页
function setHome(obj,vrl,info){
	if(!ifie()){
		alert(info);
	}
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch(e){
				alert("Your Browser does not support");
			}
			var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
				prefs.setCharPref('browser.startup.homepage',vrl);
		}
	}
}

//添加收藏
function addFavorite(info){
	if(!ifie()){
		alert(info);
	}
	var vDomainName=window.location.href;
	var description=document.title;
	try{
		window.external.AddFavorite(vDomainName,description);
	}catch(e){
		window.sidebar.addPanel(description,vDomainName,"");
	}
}

//图片大小自动脚本
function autoResizeImage(maxWidth, maxHeight, objImg) {
    var img = new Image();
    img.src = objImg.src;
    var hRatio;
    var wRatio;
    var Ratio = 1;
    var w = img.width;
    var h = img.height;
    wRatio = maxWidth / w;
    hRatio = maxHeight / h;
    if (maxWidth == 0 && maxHeight == 0) {
        Ratio = 1;
    } else if (maxWidth == 0) { //
        if (hRatio < 1) Ratio = hRatio;
    } else if (maxHeight == 0) {
        if (wRatio < 1) Ratio = wRatio;
    } else if (wRatio < 1 || hRatio < 1) {
        Ratio = (wRatio <= hRatio ? wRatio : hRatio);
    }
    if (Ratio < 1) {
        w = w * Ratio;
        h = h * Ratio;
    }
    objImg.height = h;
    objImg.width = w;
}

